<template>
  <div class="login-container">
    <div class="title1">
      <div style="font-size: 40px"><h1>Learning Platform</h1></div>
      <div style="font-size: 23px">基于云原生的在线编程学习平台</div>
    </div>

    <el-card>
      <el-form ref="loginForm" :model="loginForm" class="login-form" label-width="80px">
        <h1 class="title">管理员账号密码登录</h1>
        <el-form-item label="账号" prop="email">
          <el-input v-model="loginForm.username" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="verificationCode">
          <el-input show-password v-model="loginForm.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="margin-left: 100px" @click="login">登录</el-button>
        </el-form-item>
        <el-link @click="user" style="float: right;margin-bottom: 10px">用户登录</el-link>
      </el-form>
    </el-card>

  </div>
</template>

<script>

import { setToken } from '@/utils/auth'
import {login} from "@/api/admin";
export default {
  name:"adminLogin",
  data() {
    return {
      loginForm: {
        username : 'admin',
        password: 'admin',
      },
      token:'',
    }
  },
  methods: {
    user(){
      this.$router.push('/login')
    },
    login() {
        login({
          username: this.loginForm.username,
          password: this.loginForm.password
        }).then(data => {
          this.token = data.data
          if (this.token) {
            setToken(this.token)
            this.$router.push({ path: '/admin/home' })
          }
        }).catch((res)=>{
          console.log(res)
        })
    }
  },
}
</script>

<style>
.title1{
  justify-content: center;
  align-items: center;
  color: white;
  display: flex;
  flex-direction: column;
  margin-right: 400px;
}
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 200px;
}

.login-form {
  width: 400px;
}

.title {
  font-size: 24px;
  margin-bottom: 20px;
  text-align: center;
}
</style>

